package dao;

import util.DBHelper;

import java.util.List;
import java.util.Map;

public class ProductImage {

    public int addImage(String proid,String image){
        String sql = "insert into product_image values(default,?,?)";
        return DBHelper.update(sql,proid,image);
    }

    public List<Map<String,Object>> queryImage(String proid){
        String sql = "select images,proid,imageid from product_image where proid = ?";
        return DBHelper.selectListMap(sql,proid);
    }

    //根据图片id删除图片
    public int deleteImage(String imageid){
        String sql = " delete from product_image where imageid = ?";
        return DBHelper.update(sql,imageid);
    }

    //根据商品编号获取 主 图片
    public Map<String, Object> GetMainImage(String proid){
        String sql = "select image from shopping_product where proid = ? ";
        return DBHelper.selectOneMap(sql,proid);
    }

    //根据商品id获取 六 图片
    public List<Map<String, Object>> GetOtherImage(String proid){
        String sql = "select images from product_image where proid = ? limit 0,6";
        return DBHelper.selectListMap(sql,proid);
    }

    //根据商品id获取所有图片
    public List<Map<String, Object>> GetAllImages(String proid){
        String sql = "select images from product_image where proid = ?";
        return DBHelper.selectListMap(sql,proid);
    }
}
